/**
 * 固定资产备查登记表管理初始化
 */
var AssetRegistration = {
    id: "AssetRegistrationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
AssetRegistration.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
           /* {title: '主键id', field: 'id', visible: true, align: 'center', valign: 'middle'},*/
            {title: '编码', field: 'coding', visible: true, align: 'center', valign: 'middle'},
            {title: '固定资产名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '规格型号', field: 'specification', visible: true, align: 'center', valign: 'middle'},
            {title: '单位', field: 'unit', visible: true, align: 'center', valign: 'middle'},
            {title: '数量', field: 'quantity', visible: true, align: 'center', valign: 'middle'},
            {title: '单价', field: 'unitPrice', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: '金额', field: 'amount', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: '使用人', field: 'user', visible: true, align: 'center', valign: 'middle'},
            {title: '保存地点', field: 'saveLocation', visible: true, align: 'center', valign: 'middle'},
            {title: '购买时间', field: 'purchaseTime', visiblue:true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remarks', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
AssetRegistration.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        AssetRegistration.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加固定资产备查登记表
 */
AssetRegistration.openAddAssetRegistration = function () {
    var index = layer.open({
        type: 2,
        title: '添加固定资产备查登记表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/assetRegistration/assetRegistration_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看固定资产备查登记表详情
 */
AssetRegistration.openAssetRegistrationDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '固定资产备查登记表详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/assetRegistration/assetRegistration_update/' + AssetRegistration.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除固定资产备查登记表
 */
AssetRegistration.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/assetRegistration/delete", function (data) {
            Feng.success("删除成功!");
            AssetRegistration.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("assetRegistrationId",this.seItem.id);
        ajax.start();
    }
};

AssetRegistration.formParams = function() {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['coding'] = $("#coding").val();
    queryData['specification'] = $("#specification").val();
    queryData['platform'] = $("#platform").val();
    return queryData;
}

/**
 * 查询固定资产备查登记表列表
 */
AssetRegistration.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['coding'] = $("#coding").val();
    queryData['specification'] = $("#specification").val();
    queryData['platform'] = $("#platform").val();
    AssetRegistration.table.refresh({query: AssetRegistration.formParams});
    $("#AssetRegistrationSum").remove();
    $("#AssetRegistrationTable").after(  tatol()   )
};


AssetRegistration.tatol= function(){

    var tatol;
    var ajax = new $ax(Feng.ctxPath + "/assetRegistration/tatol", function (result) {
        tatol=result;
    }, function (result) {
        Feng.error("查询失败!" + result.responseJSON.message + "!");
    });
    ajax.setData(AssetRegistration.formParams);
    ajax.start();
    var rowTem = '<div><table id="AssetRegistrationSum" data-mobile-responsive="true" data-click-to-select="false" class="table table-hover table-striped" style="margin-top: -0px;color: #2A2E36;font-size: 14px;"><tbody id="AssetRegistrationSum" >'+
        '<tr data-index="0">'+
        '<td style="text-align: center; vertical-align: middle; width: 176px;">总计：</td> '+
        '<td style="text-align: right; vertical-align: middle; "></td>'+
        '<td style="text-align: right; vertical-align: middle; "></td> '+
        '<td style="text-align: right; vertical-align: middle; "></td>'+
        '<td style="text-align: right; vertical-align: middle; "></td>'+
        '<td style="text-align: right; vertical-align: middle;  "></td>'+
        '<td style="text-align: right; vertical-align: middle;  ">'+tatol.monery+'</td>'+
        '<td style="text-align: right; vertical-align: middle; "></td>'+
        '<td style="text-align: right; vertical-align: middle; "></td>'+
        '<td style="text-align: right; vertical-align: middle; "></td>'+
        '<td style="text-align: right; vertical-align: middle; "></td>'+
        '</tr></tbody></table></div>';
    return rowTem;
}

/**
 * 导出
 */
AssetRegistration.exportAssetRegistration = function () {
        window.location.href = "/assetRegistration/load?name=" + $("#name").val()+"&coding=" + $("#coding").val()+"&specification=" + $("#specification").val()+"&platform=" + $("#platform").val();


};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
AssetRegistration.formParams = function() {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['coding'] = $("#coding").val();
    queryData['specification'] = $("#specification").val();
    queryData['platform'] = $("#platform").val();
    return queryData;
}

$(function () {
    var defaultColunms = AssetRegistration.initColumn();
    var table = new BSTable(AssetRegistration.id, "/assetRegistration/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(AssetRegistration.formParams());
    AssetRegistration.table = table.init();
	 $(".fixed-table-toolbar").after("<div style='text-align: center;vertical-align: middle;font-size: 22px;color: #6979d7;font-weight: bold;'> 固定资产备查登记表</div>");
    $("#AssetRegistrationTable").after(AssetRegistration.tatol());
	
});
